<template>
    <div class="box-column container-grid">
        <div class="box-row box-center-start info-el" style="display:flex;justify-content: space-between;">
            <div>姓名：{{ infoData.member_xm }}&emsp;&emsp;&emsp;手机号：{{ infoData.phone }}&emsp;&emsp;&emsp;用户类别：{{
                infoData.member_type == 1 ? '住户' : '员工' }}&emsp;&emsp;&emsp;有效期：{{
        infoData.start_time }}&emsp;至&emsp;{{ infoData.end_time }}</div>
            <div>
                <el-button icon="el-icon-back" class="btn-blue" @click="go('LadderScripTable')">
                    返回
                </el-button>
            </div>
        </div>
        <ux-header-search ref="searchHeader" v-bind="enquiryData" :btnsData="{ permissionsData }"
            @search="onQueryClick"></ux-header-search>
        <div class="box-flex1 table">
            <vxe-grid v-bind="tableConfig" :data="dataStore.data" :columns="table.columns">
                <template v-slot:operate="{ row }">
                    <ux-btn-group :btns="table.btns" :data="{ row, permissionsData }"></ux-btn-group>
                </template>
            </vxe-grid>
        </div>
        <div class="pagination-el box-row box-center-end">
            <el-pagination @size-change="onSizeChange" @current-change="onCurrentChange"
                :current-page="dataStore.proxy.page" :page-size="dataStore.proxy.pageSize" :page-sizes="dataStore.pageSizes"
                :total="dataStore.pagination.total" :layout="'total, sizes, prev, pager, next, jumper'"></el-pagination>
        </div>
        <dialogForm ref="dialogForm" @submitSuccess="onSubmitSuccess" @closeDialog="onCloseDialog"></dialogForm>
        <portSetForm ref="portSetForm" @submitSuccess="onSubmitSuccess" @closeDialog="onCloseDialog"></portSetForm>
    </div>
</template>

<script  lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { Action, State } from 'vuex-class';
import { mixinTableStore } from '@/mixin/table/Store';
import { mixinTableHeader } from '@/mixin/table/Header';
import { mixinTableOperation } from '@/mixin/table/Operation';
import { mixinDialogFormParent } from '@/mixin/dialog/FormParent';
import { mixinAccess } from '@/mixin/Access';
import { mixinTabPage } from '@/mixin/tab/Page';
import dialogForm from './Edit.vue';
import portSetForm from './PortSet.vue';
@Component({
    mixins: [
        mixinTableStore,
        mixinTableHeader,
        mixinTableOperation,
        mixinDialogFormParent,
        mixinAccess,
        mixinTabPage
    ],
    components: {
        dialogForm, portSetForm
    }
})
export default class scripPortTable extends Vue {
    @Action('equipmentLadderscrip/scripLadder') getList: any;
    @Action('equipmentLadderscrip/portLadderDel') itemDel: any;
    @State((state) => state.sharing.tkLayer) tkLayerData: any;
    infoData: any = {};
    editInit({ data }) {
        const me = this as any;
        me.infoData = data;
        me.lodaByDefaultParams({ scrip_sn: data.scrip_sn });
    }

    dataStore: any = {
        proxy: {
            autoLoad: false
        }
    };
    table: any = {
        btns: [
            {
                label: '分层授权',
                param: 'portSetForm',
                condition: ['permissionsData.port'],
                enabledCondition: [
                    function ({ row }) {
                        return row.tk_layer == 1;
                    }
                ],
                handleClick: (this as any).onEditClick
            },
            {
                label: '删除',
                condition: ['permissionsData.del'],
                handleClick: (this as any).onDelClick
            }
        ],
        // 列配置
        columns: [
            {
                width: 70,
                type: 'seq',
                title: '序号'
            },
            {
                width: 150,
                title: '梯控名称',
                field: 'door_name'
            },
            {
                width: 150,
                title: '梯控guid',
                field: 'door_guid'
            },
            {
                width: 150,
                title: '梯控分层',
                field: 'tk_layer',
                params: 'tkLayerData',
                formatter: (this as any).formatterData
            },
            {
                width: 130,
                title: '在线状态',
                field: 'door_status',
                formatter: function ({ cellValue }) {
                    return ['', '在线', '离线'][cellValue];
                },
                className: function ({ row }) {
                    return ['', 'green ', 'red'][row.door_status];
                }
            },
            {
                width: 130,
                title: '授权状态',
                field: 'status',
                formatter: function ({ cellValue }) {
                    return ['', '启用', '禁用'][cellValue];
                },
                className: function ({ row }) {
                    return ['', 'green ', 'red'][row.status];
                }
            },
            {
                title: '授权楼层',
                field: 'ladder_port_str',
                formatter: function ({ row }) {
                    return row.tk_layer == 1 ? row.ladder_port_str : '所有楼层';
                }
            },
            {
                width: 120,
                title: '下发状态',
                field: 'scrip_down',
                formatter: function ({ cellValue }) {
                    return ['', '下发成功', '等待下发', '下发失败'][cellValue];
                },
                className: function ({ row }) {
                    return ['', 'green', '', 'red'][row.scrip_down];
                }
            },
            {
                width: 150,
                title: '下发时间',
                field: 'down_at',
                formatter: function ({ row }) {
                    return row.scrip_down == 2 ? '' : row.down_at;
                }
            },
            {
                width: 150,
                title: '备注',
                field: 'remark',
                formatter: function ({ row }) {
                    return row.scrip_down == 2 ? '' : row.remark;
                }
            },
            {
                slots: { default: 'operate' },
                title: '操作',
                fixed: 'right',
                field: 'operate',
                width: 160
            }
        ]
    };
    // 查询头配置
    enquiryData: any = {
        fields: [
            {
                field: 'door_name',
                label: '梯控名称'
            },
            {
                field: 'door_guid',
                label: '梯控guid'
            }
        ],
        btns: [
            {
                label: '添加',
                class: 'btn-blue',
                condition: ['permissionsData.add'],
                icon: 'el-icon-plus',
                handleClick: (this as any).onAddInitClick
            }
        ]
    };
    onAddInitClick() {
        const me = this as any;
        me.setDialogValue('selectItem', me.infoData);
        me.onAddClick();
    }
}
</script>
